package com.crawler.handler;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestHandler {

	public static void main(String[] args) {
		System.out.println("开始执行程序....");
		//计数器,保存需要循环的个数
		CountDownLatch countDownLatch = new CountDownLatch(32);
		ExecutorService service = Executors.newFixedThreadPool(32);
		for (int i = 1; i <= 32; i++) {
			Hander h = new Hander(i,countDownLatch);
			service.execute(h);
			System.out.println("第一层业务"+i+"执行开始");
		}
		try {
			countDownLatch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("程序结束....");
	}
}

class Hander extends Thread{
	CountDownLatch latch;
	int i;
	Hander(int i,CountDownLatch latch){
		this.latch = latch;
		this.i = i;
	}
	@Override
	public void run() {
		System.out.println("线程"+Thread.currentThread().getName()+"第"+i+"层业务开始执行");
		latch.countDown();
	}
	
}